<template>
  <!-- 分类 -->
  <div class="sort" v-title :data-title="$t('router.classifyJazzTitle')">
    <v-nav></v-nav>
    <div
      class="list"
      v-infinite-scroll="load"
      infinite-scroll-disabled="isPage"
      infinite-scroll-delay="120"
      infinite-scroll-distance="10"
      infinite-scroll-immediate="false"
    >
      <Cover
        :listData="list"
        :loading="loading"
        :toName="'jazzSortList'"
        v-loading="fullscreenLoading"
      ></Cover>
    </div>
    <nice-empty
      v-show="list.length == 0 && fullscreenLoading == false"
      :emptyText="$t('public.noData')"
    ></nice-empty>
    <div class="page-wrap" v-show="isPage">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-size="params.pageSize"
        background
        hide-on-single-page
        layout="total, prev, pager, next, jumper"
        :total="total"
        :small="isMobile"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import vNav from "@/components/common/header/Nav";
import Cover from "@/components/common/Cover/Index";
export default {
  data() {
    return {
      list: [],
      //数据载入动画
      fullscreenLoading: true,
      // 是否显示加载动画
      loading: false,
      //是否禁止加载数据或分页
      isPage: false,
      // 请求参数
      params: {
        // 返回数量
        pageSize: 30,
        // 当前页数
        pageNum: 1,
      },
      total: 0, //总条数
    };
  },
  components: {
    vNav,
    Cover,
  },
  computed: {
    isMobile() {
      return this.$store.getters.isMobile;
    },
    isIE() {
      return this.$store.getters.isIE;
    },
  },
  watch: {},
  mounted() {
    if (this.isIE) {
      this.params.pageSize = 50;
    }
    this.getCategoryPage();
  },
  methods: {
    //分页 每页条数
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.getCategoryPage();
    },
    //当前页
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list = [];
      this.getCategoryPage();
    },
    //获取分类下专辑列表
    async getCategoryPage() {
      this.fullscreenLoading = true;
      try {
        let res = await this.$api.jazz.getCategoryPage(this.params);
        if (res.code === 1000000) {
          this.list = res.source
            ? this.utils.processingData(this.list, res.source)
            : [];
          this.total = res.total;
          this.fullscreenLoading = false;
          if (res.size < 48 && res.size < res.total) {
            this.loading = true;
            this.isPage = false;
          } else {
            this.loading = false;
            this.isPage = true;
          }
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 加载更多
    load() {
      if (this.isMobile) {
        this.params.pageSize += 18;
      } else {
        this.params.pageSize += 20;
      }
      this.getCategoryPage();
    },
  },
};
</script>

<style lang="scss" scoped></style>
